﻿using System;
using Microsoft.Xna.Framework;


namespace LoD.WPClientLibrary.Helper {
    public static class CollisionDetection {
        public static bool BoundaryCollision(this Rectangle a, Rectangle b) {
            return a.Intersects(b);
        }

        public static bool RadialCollision(this Sprite a, Sprite b) {
            // ReSharper disable PossibleLossOfFraction
            var radius1 = a.Image.Width / 2;
            var radius2 = b.Image.Width / 2;
            // ReSharper restore PossibleLossOfFraction
            return RadialCollision(a.Position, b.Position, radius1, radius2);
        }

        public static bool RadialCollision(Vector2 a, Vector2 b, float radius1, float radius2) {
            var dist = Distance(a, b);
            return (dist < radius1 + radius2);
        }

        public static float Distance(this Vector2 a, Vector2 b) {
            double diffX = a.X - b.X;
            double diffY = a.Y - b.Y;
            var dist = Math.Sqrt(Math.Pow(diffX, 2) + Math.Pow(diffY, 2));
            return (float)dist;
        }
    }
}